package mh.demo.other.jwt;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.DecodedJWT;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Map;

public class JwtUtil {

    private JwtUtil() {
    }

    private static final String SECRET = "secret";

    public static String createToken(Map<String, Object> headerClaims, Map<String, ?> payloadClaims) {
        return JWT.create()
                .withHeader(headerClaims)
                .withPayload(payloadClaims)
                .withExpiresAt(LocalDateTime.now().plusMinutes(30L).toInstant(ZoneOffset.UTC))
                .sign(Algorithm.HMAC256(SECRET));
    }

    public static DecodedJWT verify(String token) {
        return JWT.require(Algorithm.HMAC256(SECRET)).build().verify(token);
    }

}
